package com.easyadmin.pro.common.page;

import com.github.pagehelper.PageInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * packageName com.easyadmin.pro.common.page
 *
 * @author 骑着蚂蚁去上天
 * @version JDK 17
 * @className PageResponse
 * @date 2024/4/10
 * @description 分页数据
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class PageResponse<T> {

    /**
     * 总条数
     */
    private Integer total;

    /**
     * 总页数
     */
    private Integer current;

    /**
     * 当前页码
     */
    private Integer pageNo;

    /**
     * 数据
     */
    private List<T> records;

    /**
     * 返回数据对象
     * @param pageInfo
     * @return
     */
    public static PageResponse page(PageInfo pageInfo) {
        return new PageResponse()
                .setTotal((int) pageInfo.getTotal())
                .setRecords(pageInfo.getList())
                .setPageNo(pageInfo.getPageNum())
                .setCurrent(pageInfo.getPages());
    }
}